// set function parseTime,formatTime to filter
export { parseTime, formatTime } from '@/utils'
export * from './auth_filter'
import moment from 'moment'
moment.lang('zh-cn')
function pluralize(time, label) {
  if (time === 1) {
    return time + label
  }
  return time + label + 's'
}

export function timeAgo(time) {
  const between = Date.now() / 1000 - Number(time)
  if (between < 3600) {
    return pluralize(~~(between / 60), ' minute')
  } else if (between < 86400) {
    return pluralize(~~(between / 3600), ' hour')
  } else {
    return pluralize(~~(between / 86400), ' day')
  }
}

/* 数字 格式化*/
export function numberFormatter(num, digits) {
  const si = [
    { value: 1e18, symbol: 'E' },
    { value: 1e15, symbol: 'P' },
    { value: 1e12, symbol: 'T' },
    { value: 1e9, symbol: 'G' },
    { value: 1e6, symbol: 'M' },
    { value: 1e3, symbol: 'k' }
  ]
  for (let i = 0; i < si.length; i++) {
    if (num >= si[i].value) {
      return (num / si[i].value + 0.1).toFixed(digits).replace(/\.0+$|(\.[0-9]*[1-9])0+$/, '$1') + si[i].symbol
    }
  }
  return num.toString()
}

export function toThousandslsFilter(num) {
  return (+num || 0).toString().replace(/^-?\d+/g, (m) => m.replace(/(?=(?!\b)(\d{3})+$)/g, ','))
}

// 判断是不是 null
export function judgeNull(null_i) {
  if (isNull(null_i)) {
    return ''
  }
}

// 0:未知 1:男 2:女
export function judgeSex(Sex) {
  if (Sex === 1) {
    return '男'
  } else if (Sex === 2) {
    return '女'
  } else {
    return '未知'
  }
}

// 1001是平台管理员，2001是普通用户
export function judgeRole(role) {
  if (role === 1001) {
    return '平台管理员'
  } else if (role === 2001) {
    return '普通用户'
  } else {
    return '未知'
  }
}

// 1:H5,2:Android,3:iOS
export function judgeSource(source) {
  if (source === 1) {
    return 'H5'
  } else if (source === 2) {
    return 'Android'
  } else if (source === 3) {
    return 'iOS'
  }
}

// 0：禁用 1：正常 状态
export function judgeStatus(status) {
  if (status === 0) {
    return '禁用'
  } else if (status === 1) {
    return '正常'
  }
}

// formate time
export function formateTime(time) {
  console.log('formate_time')
  console.log(moment(time).format('MMMM Do YYYY, h:mm:ss a'))
  return 	moment(time).format('MMMM Do YYYY, h:mm:ss a')
}

export function formateTimeOri(time) {
  const temp = new Date(time).getTime()
  console.log(moment(temp).format('MMMM Do YYYY, h:mm:ss a'))
  return moment(temp).format('MMMM Do YYYY, h:mm:ss a')
}

// mgz

// 0:取消 1:正常
export function mgzStatus(status) {
  if (status == 0) {
    return '正常'
  } else if (status == 1) {
    return '禁用'
  }
}

// version
//
// 0:默认 1:iOS 2:Android
export function verType(status) {
  if (status == 0) {
    return '默认'
  } else if (status == 1) {
    return 'iOS'
  } else {
    return 'Android'
  }
}

//	0:没上架 1:上架中 2:上架成功
export function Jshelftype(status) {
  if (status == 0) {
    return '没上架'
  } else if (status == 1) {
    return '上架中'
  } else if (status == 2) {
    return '上架成功'
  } else {
    return '没有信息'
  }
}

// 0:不强制 1:强制更新
export function Jforce(status) {
  if (status == 0) {
    return '不强制'
  } else if (status == 1) {
    return '强制更新'
  } else {
    return '没有信息'
  }
}

// 0:取消 1:正常
export function Jstatus(status) {
  if (status == 0) {
    return '取消'
  } else if (status == 1) {
    return '正常'
  } else {
    return '没有信息'
  }
}

// 举报类型

// 0:举报 1:不举报
export function Jreport(status) {
  if (status == 0) {
    return '举报'
  } else if (status == 1) {
    return '不举报'
  }
}

// 用户举报
// 0:忽略 1:未处理(APP端显示已提交) 2:平台人工处理 3:系统处理
export function UserReportJ(status) {
  if (status == 0) {
    return '忽略'
  } else if (status == 1) {
    return '未处理'
  } else if (status == 2) {
    return '平台人工处理'
  } else if (status == 3) {
    return '系统处理'
  }
}

// topic
// 	101:普通文章 201:公告文章 301:新闻公告
export function TopicReportJ1(status) {
  if (status == 101) {
    return '普通文章'
  } else if (status == 201) {
    return '公告文章'
  } else if (status == 301) {
    return '新闻公告'
  }
}

// 状态是否使用

export function UserOrNot(status) {
  if (status == 1) {
    return '使用'
  } else if (status == 0) {
    return '停用'
  }
}


//gift
//打折
// 0:不打折 1:打折
export function dazhe(status) {
  if (status == 0) {
    return '不打折'
  } else if (status == 1) {
    return '打折'
  }
}

	
// 0:普通礼物 1:高级礼物
export function gift_s(status) {
  if (status == 0) {
    return '普通礼物'
  } else if (status == 1) {
    return '高级礼物'
  }
}